import { Provide, Body, Inject, Post, Get, Query } from '@midwayjs/decorator';
import { CoolController, BaseController, CoolEps } from '@cool-midway/core';
import { DoupiaopiaoLoginService } from '../../service/login';
import { Context } from '@midwayjs/koa';
import { DoupiaopiaoOrderService } from '../../service/order';

/**
 * 不需要登录的后台接口
 */
@Provide()
@CoolController()
export class DoupiaopiaoAppOpenController extends BaseController {
  @Inject()
  doupiaopiaoLoginService: DoupiaopiaoLoginService;

  @Inject()
  doupiaopiaoOrderService: DoupiaopiaoOrderService;

  @Inject()
  ctx: Context;

  @Inject()
  eps: CoolEps;

  /**
   * 实体信息与路径
   * @returns
   */
  @Get('/eps', { summary: '实体信息与路径' })
  public async getEps() {
    return this.ok(this.eps.admin);
  }

  /**
   * 抖音小程序登录
   * @param login
   */
  @Post('/dyLogin', { summary: '抖音登录' })
  async dyLogin(@Body() body) {
    const res = await this.doupiaopiaoLoginService.douyinLogin(body);
    return this.ok(res);
  }

  // 淘宝小程序登录
  @Post('/tbLogin', { summary: '淘宝登录' })
  async tbLogin(@Body() body) {
    const res = await this.doupiaopiaoLoginService.taobaoLogin(body);
    return this.ok(res);
  }

  //出票回调
  @Post('/payCallBack', { summary: '支付回掉接口' })
  async payCallBack(@Body() body) {
    const res = await this.doupiaopiaoOrderService.payCallBack(body);
    return this.ok(res);
  }
  // //确认下单接口
  // @Get('/pay', { summary: '确定下单' })
  // async pagMent(@Query() query) {
  //   const res = await this.doupiaopiaoOrderService.payMoney(query);
  //   return this.ok(res);
  // }
  //支付回调地址
  @Post('/orderIsComplete', { summary: '支付回调' })
  async orderIsComplete(@Body() body) {
    const res = await this.doupiaopiaoOrderService.orderStatusBack(body);
    return this.ok(res);
  }

  //退款回调
  @Post('/refundIsComplete', { summary: '退款回调' })
  async refundIsComplete(@Body() body) {
    const res = await this.doupiaopiaoOrderService.orderRefund(body);
    return this.ok(res);
  }
  //生成二维码
  @Get('/qrcode', { summary: '生成二维码' })
  async setCode(@Query() query) {
    const res = await this.doupiaopiaoOrderService.Qrcode(query);
    return this.ok(res);
  }

  @Post('/getData', { summary: '咸鱼解密返回' })
  async getDecryptData(@Body() body) {
    const res = await this.doupiaopiaoOrderService.DecryptData(body);
    return this.ok(res);
  }

  // /**
  //  * 登录
  //  * @param login
  //  */
  // @Post('/login', { summary: '登录' })
  // @Validate()
  // async login(@Body() login: LoginDTO) {
  //   return this.ok(await this.businessLoginService.login(login));
  // }

  // /**
  //  * 获得验证码
  //  */
  // @Get('/captcha', { summary: '验证码' })
  // async captcha(
  //   @Query('type') type: string,
  //   @Query('width') width: number,
  //   @Query('height') height: number
  // ) {
  //   return this.ok(
  //     await this.businessLoginService.captcha(type, width, height)
  //   );
  // }

  // /**
  //  * 刷新token
  //  */
  // @Get('/refreshToken', { summary: '刷新token' })
  // async refreshToken(@Query('refreshToken') refreshToken: string) {
  //   return this.ok(await this.businessLoginService.refreshToken(refreshToken));
  // }
}
